<?php
/**
 *
 * 版权所有：恰维网络<qwadmin.qiawei.com>
 * 作    者：寒川<hanchuan@qiawei.com>
 * 日    期：2016-09-20
 * 版    本：1.0.0
 * 功能说明：后台首页控制器。
 *
 **/

namespace Qwadmin\Controller;

class IndexController extends ComController
{
    public function index()
    {
        $time = date('Y-m-d');
        $ming = date('Y-m-d',strtotime('+1 day'));
        $hou = date('Y-m-d',strtotime('+2 day'));
        // $lhou = date('Y-m-d',strtotime('+3 day'));
        //查询今天勾餐是否展示
        $clist = M('can')->where(['s_time'=>$time])->select();
        $cclist = M('can')->where(['time'=>['in',array($ming,$hou)]])->select();

    
        $mm[] = $cclist[0];

     
        
        
        if (empty($cclist[1])) {
            $hh = '1';
        }else{
            $hh[] = $cclist[1];
        }
        //    dump($hh);
        // exit;
        $this->assign('ming',$ming);
        $this->assign('hou',$hou);
        $this->assign('mm',$mm);
        $this->assign('hh',$hh);
        $this->assign('clist',$clist);
        //查询用户今天是否勾餐
        $dada = M('member')->where(array('uid'=>$_SESSION['uid']))->select();
        $uname = $dada[0]['user'];
        $time = date('Y-m-d');
        $c = M("ucan")->where(['uname'=>$uname,'s_time'=>$time])->select();
        foreach ($c as $key => $value) {
            if ($value['time'] == $ming) {
                $mc[] = $value;
            }
            if ($value['time'] == $hou) {
                $hc[] = $value;
            }
        }
        // dump($c[0]['c_id']);
        // dump($mc);
        // dump($hh);
        // exit;
            if ($mc[0]['c_id'] == $mm[0]['id'] && $hc[0]['c_id'] == $hh[0]['id']) {
                    $m='1';
                    $h = '1';
            }else{
                    if ($mc[0]['c_id'] == $mm[0]['id']) {
                        $m = '1';
                    }else{
                        if ($hc[0]['c_id'] == $hh[0]['id']) {
                            $h = '1';
                        }else{
                           
                        }
                    }
            }
        
        // echo $m .'-'.$h;
        // exit;
            
            // $shi = date('H');
            // // $fen = date('s');
            // // echo $sfm.'='.'17:20';
            // // exit;
            // if ($shi >= '17' && $shi <= '24') {
            //     # code...
            // }
            // dump($sfm);
            // exit;
            
            $jcan = M('can')->where(['s_time'=>$time])->select();
            // dump($jcan);
            // exit;
            if ($jcan[0]['off'] == '1') {
                $off = '1';
            }
            $this->assign('off',$off);
            $this->assign('m',$m);
            $this->assign('h',$h);

        //查询用户权限
        $mtype = $dada[0]['m_type'];
        $this->assign('mtype',$mtype);
        //查询申请数量
        $fnum = M("cost")->where(['uname'=>$uname])->count(); //费用报销
        $bnum = M("look")->where(['uname'=>$uname,'type'=>0,'que'=>0])->count(); //办公用品
        $ynum = M("look")->where(['uname'=>$uname,'type'=>3])->count(); //月度需求
        $jnum = M("look")->where(['uname'=>$uname,'type'=>1])->count(); //急性需求
        $gnum = M("look")->where(['uname'=>$uname,'type'=>2])->count(); //固定资产
        $cnum = M("turn")->where(['uname'=>$uname])->count(); //派车申请
        $this->assign('fnum',$fnum);
        $this->assign('bnum',$bnum);
        $this->assign('ynum',$ynum);
        $this->assign('jnum',$jnum);
        $this->assign('gnum',$gnum);
        $this->assign('cnum',$cnum);
        $gid = M('auth_group_access')->where(['uid'=>$_SESSION['uid']])->select();
        // dump($gid);
        // exit;
        $glist = M('auth_group')->where(['id'=>$gid[0]['group_id']])->select();
        $apost = $glist[0]['post'];
        // dump($apost);
        // exit;
        //查询今日公告;
        $gao = M('gong')->order('id desc')->find();
        $title = $gao['title'];
        $content = $gao['conter'];
        // echo $content;
        // dump($gao);
        // exit;
        $this->assign('title',$title);
        $this->assign('content',$content);

        //查询审批数量
        switch ($mtype) {
            case '2'://主管
               
                $ffnum = M('cost')->where(['ment'=>$apost,'look'=>0,'ju'=>0])->count();//费用报销
                $bbnum = M('look')->where(['ment'=>$apost,'look'=>0,'ju'=>0,'type'=>0])->count();//办公用品
                $yynum = M('look')->where(['ment'=>$apost,'look'=>0,'ju'=>0,'type'=>3])->count();
                $jjnum = M('look')->where(['ment'=>$apost,'look'=>0,'ju'=>0,'type'=>1])->count();
                $ggnum = M('look')->where(['ment'=>$apost,'look'=>0,'ju'=>0,'type'=>2])->count();
                $ccnum = M('turn')->where(['ment'=>$apost,'look'=>0,'ju'=>0])->count();
                $this->assign('ffnum',$ffnum);
                $this->assign('bbnum',$bbnum);
                $this->assign('yynum',$yynum);
                $this->assign('jjnum',$jjnum);
                $this->assign('ggnum',$ggnum);
                $this->assign('ccnum',$ccnum);
                break;
            case '3'://经理
                switch ($apost) {
                    case '行政中心':
                            $ffnum = M('cost')->where(['ment'=>$apost,'look'=>8,'ju'=>0])->count();//费用报销
                            $bbnum = M('look')->where(['ment'=>$apost,'look'=>8,'ju'=>0,'type'=>0])->count();//办公用品
                            $yynum = M('look')->where(['ment'=>$apost,'look'=>8,'ju'=>0,'type'=>3])->count();
                            $jjnum = M('look')->where(['ment'=>$apost,'look'=>8,'ju'=>0,'type'=>1])->count();
                            $ggnum = M('look')->where(['ment'=>$apost,'look'=>8,'ju'=>0,'type'=>2])->count();
                            $ccnum = M('turn')->where(['ment'=>$apost,'look'=>8,'ju'=>0])->count();
                            $this->assign('ffnum',$ffnum);
                            $this->assign('bbnum',$bbnum);
                            $this->assign('yynum',$yynum);
                            $this->assign('jjnum',$jjnum);
                            $this->assign('ggnum',$ggnum);
                            $this->assign('ccnum',$ccnum);
                        break;
                    case '财务中心':
                            $ffbnum = M('cost')->where(['ment'=>$apost,'look'=>10,'ju'=>0])->count();//费用报销
                            $ffgnum = M('cost')->where(['look'=>3,'ju'=>0])->count();//费用报销
                            $ffnum = $ffbnum + $ffgnum;
                            $bbnum = M('look')->where(['ment'=>$apost,'look'=>10,'ju'=>0,'type'=>0,'que'=>0])->count();//办公用品
                            // $bbgnum = M('look')->where(['look'=>3,'ju'=>0,'type'=>0,'que'=>0])->count();//办公用品
                            // $bbnum = $bbbnum + $bbgnum;
                            $yybnum = M('look')->where(['ment'=>$apost,'look'=>10,'ju'=>0,'type'=>3])->count();
                            $yygnum = M('look')->where(['num'=>array('exp',' >number '),'type'=>3,'look'=>3,'ju'=>0])->count();
                            $yynum = $yybnum + $yygnum;
                            $jjbnum = M('look')->where(['ment'=>$apost,'look'=>10,'ju'=>0,'type'=>1])->count();
                            $jjgnum = M('look')->where(['type'=>1,'look'=>3,'ju'=>0])->count();
                            $jjnum = $jjbnum + $jjgnum;
                            $ggbnum = M('look')->where(['ment'=>$apost,'look'=>10,'ju'=>0,'type'=>2])->count();
                            $gggnum = M('look')->where(['type'=>2,'look'=>3,'ju'=>0])->count();
                            $ggnum = $ggbnum + $gggnum;
                            $ccnum = M('turn')->where(['ment'=>$apost,'look'=>10,'ju'=>0])->count();
                            $this->assign('ffnum',$ffnum);
                            $this->assign('bbnum',$bbnum);
                            $this->assign('yynum',$yynum);
                            $this->assign('jjnum',$jjnum);
                            $this->assign('ggnum',$ggnum);
                            $this->assign('ccnum',$ccnum);
                        break;
                    case '采购中心':
                            $ffnum = M('cost')->where(['ment'=>$apost,'look'=>9,'ju'=>0])->count();//费用报销
                            $bbnum = M('look')->where(['ment'=>$apost,'look'=>9,'ju'=>0,'type'=>0])->count();//办公用品
                           
                            $yynum = M('look')->where(['ment'=>$apost,'look'=>9,'ju'=>0,'type'=>3])->count();
                            $jjnum = M('look')->where(['ment'=>$apost,'look'=>9,'ju'=>0,'type'=>1])->count();
                            $ggnum = M('look')->where(['ment'=>$apost,'look'=>9,'ju'=>0,'type'=>2])->count();
                            $ccnum = M('turn')->where(['ment'=>$apost,'look'=>9,'ju'=>0])->count();
                            $this->assign('ffnum',$ffnum);
                            $this->assign('bbnum',$bbnum);
                            $this->assign('yynum',$yynum);
                            $this->assign('jjnum',$jjnum);
                            $this->assign('ggnum',$ggnum);
                            $this->assign('ccnum',$ccnum);
                        break;
                }
                
                break;
            case '4'://行政
                
                // $ffnum = M('cost')->where(['look'=>2,'ju'=>0])->count();//费用报销
                $bbnum = M('look')->where(['look'=>2,'ju'=>0,'type'=>0])->count();//办公用品
                $yynum = M('look')->where(['look'=>2,'ju'=>0,'type'=>3])->count();
                $jjnum = M('look')->where(['look'=>2,'ju'=>0,'type'=>1])->count();
                $ggnum = M('look')->where(['look'=>2,'ju'=>0,'type'=>2])->count();
                $ccnum = M('turn')->where(['look'=>2,'ju'=>0])->count();
                $this->assign('ffnum',$ffnum);
                $this->assign('bbnum',$bbnum);
                $this->assign('yynum',$yynum);
                $this->assign('jjnum',$jjnum);
                $this->assign('ggnum',$ggnum);
                $this->assign('ccnum',$ccnum);
                break;
            case '5'://财务
                
                // $ffnum = M('cost')->where(['look'=>2,'ju'=>0])->count();//费用报销
                // $bbnum = M('look')->where(['look'=>2,'ju'=>0,'type'=>0])->count();//办公用品
                $yynum = M('look')->where(['look'=>3,'ju'=>0,'type'=>3])->count();
                $jjnum = M('look')->where(['look'=>3,'ju'=>0,'type'=>1])->count();
                $ggnum = M('look')->where(['look'=>3,'ju'=>0,'type'=>2])->count();
                // $ccnum = M('turn')->where(['look'=>2,'ju'=>0])->count();
                $this->assign('ffnum',$ffnum);
                // $this->assign('bbnum',$bbnum);
                $this->assign('yynum',$yynum);
                $this->assign('jjnum',$jjnum);
                $this->assign('ggnum',$ggnum);
                // $this->assign('ccnum',$ccnum);
                break;
            case '10'://财务
                
                $ffnum = M('cost')->where(['look'=>2,'ju'=>0])->count();//费用报销
                // $bbnum = M('look')->where(['look'=>2,'ju'=>0,'type'=>0])->count();//办公用品
                $yynum = M('look')->where(['look'=>3,'ju'=>0,'type'=>3])->count();
                $jjnum = M('look')->where(['look'=>3,'ju'=>0,'type'=>1])->count();
                $ggnum = M('look')->where(['look'=>3,'ju'=>0,'type'=>2])->count();
                // $ccnum = M('turn')->where(['look'=>2,'ju'=>0])->count();
                $this->assign('ffnum',$ffnum);
                // $this->assign('bbnum',$bbnum);
                $this->assign('yynum',$yynum);
                $this->assign('jjnum',$jjnum);
                $this->assign('ggnum',$ggnum);
                // $this->assign('ccnum',$ccnum);
                break;
            case '8'://网络中心
                
                $ffnum = M('cost')->where(['look'=>1,'ju'=>0])->count();//费用报销
                $bbnum = M('look')->where(['look'=>1,'ju'=>0,'type'=>0])->count();//办公用品
                $yynum = M('look')->where(['look'=>1,'ju'=>0,'type'=>3])->count();
                $jjnum = M('look')->where(['look'=>1,'ju'=>0,'type'=>1])->count();
                $ggnum = M('look')->where(['look'=>1,'ju'=>0,'type'=>2])->count();
                $ccnum = M('turn')->where(['look'=>1,'ju'=>0])->count();
                $this->assign('ffnum',$ffnum);
                $this->assign('bbnum',$bbnum);
                $this->assign('yynum',$yynum);
                $this->assign('jjnum',$jjnum);
                $this->assign('ggnum',$ggnum);
                $this->assign('ccnum',$ccnum);
                break; 
            case '9'://职能中心
                    $mlist = M('auth_group')->where(['mtype'=>2])->select();

                foreach ($mlist as $vn) {
            
                    $ments[] =  $vn['title'];
              

                }
                //部门
                $fbwhere = [
                      'ment' => [
                          'in',
                          $ments
                      ],
                      'look' => 1,
                      
                      'ju'   => 0

                ];
                //部门
                $bbwhere = [
                      'ment' => [
                          'in',
                          $ments
                      ],
                      'look' => 1,
                      'type' => 0,
                      'que'  => 0,
                      'ju'   => 0

                ];

                //部门
                $ybwhere = [
                      'ment' => [
                          'in',
                          $ments
                      ],
                      'look' => 1,
                      'type' => 3,
                      'ju'   => 0

                ];
                //部门
                $jbwhere = [
                      'ment' => [
                          'in',
                          $ments
                      ],
                      'look' => 1,
                      'type' => 1,
                      'ju'   => 0

                ];
                //部门
                $gbwhere = [
                      'ment' => [
                          'in',
                          $ments
                      ],
                      'look' => 1,
                      'type' => 2,
                      'ju'   => 0

                ];
                //部门
                $cbwhere = [
                      'ment' => [
                          'in',
                          $ments
                      ],
                      'look' => 1,
                      'pay' => 0,
                      'ju'   => 0

                ];
                $ffbnum = M('cost')->where($fbwhere)->count();//费用报销部门
                $ffgnum = M('cost')->where(['look'=>4,'ju'=>0,'type'=>0])->count();//费用报销公司
                $ffnum = $ffbnum + $ffgnum;
                // echo $ffnum;
                // exit;
                $bbnum = M('look')->where($bbwhere)->count();//办公用品
                $yybnum = M('look')->where($ybwhere)->count();
                $yygnum = M('look')->where(['look'=>4,'ju'=>0,'type'=>3])->count();
                $yynum = $yybnum + $yygnum;

                $jjbnum = M('look')->where($jbwhere)->count();
                $jjgnum = M('look')->where(['look'=>4,'ju'=>0,'type'=>1])->count();
                $jjnum = $jjbnum + $jjgnum;
                $ggbnum = M('look')->where($gbwhere)->count();
                $gggnum = M('look')->where(['look'=>4,'ju'=>0,'type'=>2])->count();
                $ggnum = $ggbnum + $gggnum;
                $ccbnum = M('turn')->where($cbwhere)->count();
                $ccgnum = M('turn')->where(['look'=>4,'ju'=>0,'pay'=>0])->count();
                $ccnum = $ccbnum + $ccgnum;
                $this->assign('ffnum',$ffnum);
                $this->assign('bbnum',$bbnum);
                $this->assign('yynum',$yynum);
                $this->assign('jjnum',$jjnum);
                $this->assign('ggnum',$ggnum);
                $this->assign('ccnum',$ccnum);
                break;
            case '6'://董事办
                
                $ffnum = M('cost')->where(['look'=>5,'ju'=>0])->count();//费用报销
                // $bbnum = M('look')->where(['look'=>1,'ju'=>0,'type'=>0])->count();//办公用品
                $yynum = M('look')->where(['look'=>5,'ju'=>0,'type'=>3])->count();
                $jjnum = M('look')->where(['look'=>5,'ju'=>0,'type'=>1])->count();
                $ggnum = M('look')->where(['look'=>5,'ju'=>0,'type'=>2])->count();
                $ccnum = M('turn')->where(['look'=>3,'ju'=>0,'type'=>2])->count();
                $this->assign('ffnum',$ffnum);
                // $this->assign('bbnum',$bbnum);
                $this->assign('yynum',$yynum);
                $this->assign('jjnum',$jjnum);
                $this->assign('ggnum',$ggnum);
                $this->assign('ccnum',$ccnum);
                break;                     
        }
        $this->display();
    }











    public function can()
    {
        
        // $list = $_POST;
        // dump($_POST['inlineRadioOptions']);
        // exit;
        if (empty($_POST['inlineRadioOptions'])) {
           $list['cname'] = $_POST['inlineRadioOptions1'];
        }else{
            $list['cname'] = $_POST['inlineRadioOptions'];
        }
        // if () {
        //     # code...
        // }
        // dump($)

        if ($list['cname'] == null ) {
            echo '没填';
            exit;
        }
        $list['c_id'] = $_POST['c_id'];
        //         dump($list);
        // exit;
        // $list['time'] = date('Y-m-d');
        $z_id = M('auth_group_access')->where(array('uid'=>$_SESSION['uid']))->select();
        $dada = M('member')->where(array('uid'=>$_SESSION['uid']))->select();
        $c_list = M('ucan')->where(['uname'=>$dada[0]['user'],'c_id'=>$list['c_id']])->select();
        if (!empty($c_list)) {
            echo '已经勾选';
            exit;
        }



        $b_id = $z_id[0]['group_id'];
        $m_list = M('auth_group')->where(array('id'=>$b_id))->select();

       /* dump($m_list);
        exit;*/
        // if ($m_list[0]['post'] == 0) {
        //     $list['ment'] = $m_list[0]['title'];
        // }else{
        //     $list['ment'] = $m_list[0]['post'];
        // }
        
        $list['uname'] = $dada[0]['user'];
        $list['ment'] = $m_list[0]['post'];
        $list['s_time'] = date('Y-m-d');
        $list['time'] = $_POST['time'];
        // dump($list);
        // exit;
        if (M('ucan')->add($list) > 0) {

              echo '成功';
          }else{
             echo '失败';
          }


        
    }








    //查看所有费用报销审批情况(员工)
    public function ffa()
    {
        $dada = M('member')->where(array('uid'=>$_SESSION['uid']))->select();
        $db = M('cost');
        $count = $db->where(['uname'=>$dada[0]['user']])->count();
                  
        $pagecount = 20;
        $page = new \Think\Page($count , $pagecount);
        // $row[] = '';
        $page->parameter = $row; //此处的row是数组，为了传递查询条件
        $page->setConfig('first','第一页');
        $page->setConfig('prev','上一页');
        $page->setConfig('next','下一页');
        $page->setConfig('last','尾页');
        $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
        $show = $page->show();
        $list = $db->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
        
        $title = '费用报销审批情况';
        // dump($list);
        // exit;
        $this->assign('list',$list);
        $this->assign('page',$show);
        $this->assign('title',$title);
        $this->display();
        



    }






    public function cha()
    {
        // dump(I());
        // exit;
        switch ($_POST['type']) {
            case '1':
                     $list = M('fei')->where(['fid'=>$_POST['id']])->find();
                    if (!empty($list)) {
                        $this->ajaxReturn($list);
                    }
                break;
            case '2':
                     $list = M('fei')->where(['fid'=>$_POST['id'],'stype'=>2])->find();
                    if (!empty($list)) {
                        $this->ajaxReturn($list);
                    }
                break;
           case '3':
                     $list = M('sh')->where(['sid'=>$_POST['id'],'stype'=>1])->find();
                    // dump($list);
                    // exit;
                    if (!empty($list)) {
                        $this->ajaxReturn($list);
                    }
                break;
            case '4':
                     $list = M('sh')->where(['sid'=>$_POST['id'],'stype'=>2])->find();
                     // dump($list);
                     // exit;
                    if (!empty($list)) {
                        $this->ajaxReturn($list);
                    }
                break;
            case '5':
                     $list = M('yue')->where(['sid'=>$_POST['id']])->find();
                     // dump($list);
                     // exit;
                    if (!empty($list)) {
                        $this->ajaxReturn($list);
                    }
                break;
            case '6':
                     $list = M('yue')->where(['sid'=>$_POST['id'],'stype'=>2])->find();
                    if (!empty($list)) {
                        $this->ajaxReturn($list);
                    }
                break;
             case '7':
                     $list = M('che')->where(['sid'=>$_POST['id'],'stype'=>1])->find();
                     // dump($list);
                     // exit;
                    if (!empty($list)) {
                        $this->ajaxReturn($list);
                    }
                break;
            case '8':
                     $list = M('che')->where(['cid'=>$_POST['id'],'stype'=>2])->find();
                    if (!empty($list)) {
                        $this->ajaxReturn($list);
                    }
                break;
        }
       
    }





    public function bfa()
    {
        // dump(I());
        // exit;
        $dada = M('member')->where(array('uid'=>$_SESSION['uid']))->select();
        $uname=$dada[0]['user'];
        switch ($_GET['type']) {
            case '0':
                $list = M('look')->where(['uname'=>$uname,'type'=>0,'que'=>0])->select();
                // dump($list);
                // exit;
                $title = '办公用品领用审批进度';
                $lei = '办公';
                $this->assign('lei',$lei);
                $this->assign('list',$list);
                $this->assign('title',$title);
                $this->display();
                break;
            case '1':
                $list =  M('look')->where(['uname'=>$uname,'type'=>3])->select();
                $title = '月度需求审批进度';
                $lei = '月度';
                $this->assign('lei',$lei);
                $this->assign('list',$list);
                $this->assign('title',$title);
                $this->display();
                break;
        }
    }





    public function qfa()
    {
        // dump(I());
        // exit;
        $dada = M('member')->where(array('uid'=>$_SESSION['uid']))->select();
        $uname=$dada[0]['user'];
        switch ($_GET['type']) {
            case '2':
                
                $list = M('look')->where(['uname'=>$uname,'type'=>1,'que'=>0])->select();
                $title = '急性物资审批进度';
                $lei = '急性';
                $this->assign('lei',$lei);
                $this->assign('list',$list);
                $this->assign('title',$title);
                $this->display();
                break;
            case '3':
                $list = M('look')->where(['uname'=>$uname,'type'=>1,'que'=>0])->select();
                $title = '固定资产审批进度';
                $lei = '固定';
                $this->assign('lei',$lei);
                $this->assign('list',$list);
                $this->assign('title',$title);
                $this->display();
                break;
        }
    }


    public function cfa()
    {
        // dump(I());
        // exit;
        $dada = M('member')->where(array('uid'=>$_SESSION['uid']))->select();
        $uname=$dada[0]['user'];
        $list = M('turn')->where(['uname'=>$uname])->select();
        // $list = M('turn')->where(['uname'=>$uname])->select();
        $title = '派车申请审批进度';
       
        $this->assign('lei',$lei);
        $this->assign('list',$list);
        $this->assign('title',$title);
        $this->display();

    }



    public function del()
    {
        dump(I());
        exit;
    }




}